/**
 * output package name
 */
package com.kingdee.eas.custom.wg.reports.client;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.ctrl.kdf.headfootdesigner.HeadFootModel;
import com.kingdee.bos.ctrl.kdf.table.ICell;
import com.kingdee.bos.ctrl.kdf.table.IColumn;
import com.kingdee.bos.ctrl.kdf.table.IRow;
import com.kingdee.bos.ctrl.kdf.table.KDTDataRequestManager;
import com.kingdee.bos.ctrl.kdf.table.KDTMergeManager;
import com.kingdee.bos.ctrl.kdf.table.KDTSelectBlock;
import com.kingdee.bos.ctrl.kdf.table.KDTSelectManager;
import com.kingdee.bos.ctrl.kdf.table.KDTViewManager;
import com.kingdee.bos.ctrl.kdf.table.KDTable;
import com.kingdee.bos.ctrl.kdf.table.event.KDTDataFillListener;
import com.kingdee.bos.ctrl.kdf.table.event.KDTDataRequestEvent;
import com.kingdee.bos.ctrl.kdf.table.event.KDTDataRequestListener;
import com.kingdee.bos.ctrl.kdf.table.event.KDTMouseEvent;
import com.kingdee.bos.ctrl.kdf.util.style.StyleAttributes;
import com.kingdee.bos.ctrl.kdf.util.style.Styles;
import com.kingdee.bos.ctrl.swing.KDDatePicker;
import com.kingdee.bos.ctrl.swing.KDWorkButton;
import com.kingdee.bos.ui.face.CoreUIObject;
import com.kingdee.bos.ui.face.IUIFactory;
import com.kingdee.bos.ui.face.IUIWindow;
import com.kingdee.bos.ui.face.ItemAction;
import com.kingdee.bos.ui.face.UIFactory;
import com.kingdee.eas.basedata.master.material.MaterialGroupInfo;
import com.kingdee.eas.basedata.master.material.MaterialGroupStandardInfo;
import com.kingdee.eas.basedata.master.material.MaterialInfo;
import com.kingdee.eas.common.client.OprtState;
import com.kingdee.eas.common.client.UIContext;
import com.kingdee.eas.common.client.UIFactoryName;
import com.kingdee.eas.custom.wg.reports.StockTransferRptFacadeFactory;
import com.kingdee.eas.framework.report.ICommRptBase;
import com.kingdee.eas.framework.report.IVirtualRptBaseFacade;
import com.kingdee.eas.framework.report.SimpleCompanyUserObject;
import com.kingdee.eas.framework.report.client.CommRptBaseConditionUI;
import com.kingdee.eas.framework.report.util.DefaultKDTableInsertHandler;
import com.kingdee.eas.framework.report.util.KDTableInsertHandler;
import com.kingdee.eas.framework.report.util.RptParams;
import com.kingdee.eas.framework.report.util.RptRowSet;
import com.kingdee.eas.scm.common.util.PrecisionUtil;
import com.kingdee.eas.scm.im.inv.client.InvClientUtils;
import com.kingdee.eas.util.SysUtil;
import com.kingdee.eas.util.client.EASResource;
import com.kingdee.eas.util.client.MsgBox;
import java.awt.event.ActionEvent;
import java.io.PrintStream;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.swing.ActionMap;
import javax.swing.JDialog;
import javax.swing.SwingUtilities;
import javax.swing.event.EventListenerList;
import org.apache.log4j.Logger;

/**
 * output class name
 */
public class StockTransferRptUI extends AbstractStockTransferRptUI
{

    public StockTransferRptUI()
        throws Exception
    {
        firstLoadData = true;
        amtPrecision = 4;
        tbl.setEditable(false);
        tbl.getActionMap().remove("Delete");
        tbl.checkParsed();
        tbl.getDataRequestManager().addDataRequestListener(this);
        tbl.getDataRequestManager().setDataRequestMode(1);
        tbl.getDataRequestManager().addDataFillListener(new KDTDataFillListener() {

            public void afterDataFill(KDTDataRequestEvent e)
            {
                tbl_afterDataFill(e);
            }

            
          
        }
);
        enableExportExcel(tbl);
        dateFrom.setEnabled(false);
        dateTo.setEnabled(false);
    }

    public void storeFields()
    {
        super.storeFields();
    }

    public void actionPageSetup_actionPerformed(ActionEvent e)
        throws Exception
    {
        super.actionPageSetup_actionPerformed(e);
    }

    public void actionExitCurrent_actionPerformed(ActionEvent e)
        throws Exception
    {
        super.actionExitCurrent_actionPerformed(e);
    }

    public void actionHelp_actionPerformed(ActionEvent e)
        throws Exception
    {
        super.actionHelp_actionPerformed(e);
    }

    public void actionAbout_actionPerformed(ActionEvent e)
        throws Exception
    {
        super.actionAbout_actionPerformed(e);
    }

    public void actionOnLoad_actionPerformed(ActionEvent e)
        throws Exception
    {
        super.actionOnLoad_actionPerformed(e);
    }

    public void actionSendMessage_actionPerformed(ActionEvent e)
        throws Exception
    {
        super.actionSendMessage_actionPerformed(e);
    }

    public void actionRefresh_actionPerformed(ActionEvent e)
        throws Exception
    {
        firstLoadData = true;
        insertRowCount = 0;
        super.actionRefresh_actionPerformed(e);
    }

    public void actionQuery_actionPerformed(ActionEvent e)
        throws Exception
    {
        firstLoadData = true;
        insertRowCount = 0;
        super.actionQuery_actionPerformed(e);
    }

    public void actionPrint_actionPerformed(ActionEvent e)
        throws Exception
    {
        super.actionPrint_actionPerformed(e);
    }

    public void actionPrintPreview_actionPerformed(ActionEvent e)
        throws Exception
    {
        super.actionPrintPreview_actionPerformed(e);
    }

    protected ICommRptBase getRemoteInstance()
        throws BOSException
    {
        return StockTransferRptFacadeFactory.getRemoteInstance();
    }

    protected KDTable getTableForPrintSetting()
    {
        return tbl;
    }

    protected CommRptBaseConditionUI getQueryDialogUserPanel()
        throws Exception
    {
        StockTransferRptConditionUI conditionUI = new StockTransferRptConditionUI();
        conditionUI.setSize(400, 300);
        return conditionUI;
    }

    protected RptParams getParamsForInit()
    {
        RptParams initParam = new RptParams();
        return initParam;
    }

    protected void query()
    {
        dateFrom.setValue(params.getObject("dateFrom"));
        dateTo.setValue(params.getObject("dateTo"));
        amtPrecision = params.getInt("amtPrecision");
        tbl.removeRows();
        super.query();
    }

    public void tableDataRequest(KDTDataRequestEvent e)
    {
        Boolean ckBxByStatUnit = (Boolean)params.getObject("ckBxByStatUnit");
        if(ckBxByStatUnit.booleanValue())
        {
            tbl.getColumn("baseUnit").getStyleAttributes().setHided(true);
            tbl.getColumn("statUnit").getStyleAttributes().setHided(false);
        } else
        {
            tbl.getColumn("statUnit").getStyleAttributes().setHided(true);
            tbl.getColumn("baseUnit").getStyleAttributes().setHided(false);
        }
        Boolean ckBxShowMShortName = (Boolean)params.getObject("ckBxShowMShortName");
        if(ckBxShowMShortName != null && ckBxShowMShortName.booleanValue())
        {
            tbl.getColumn("materialShortName").getStyleAttributes().setHided(false);
            int freezeCol = tbl.getColumnIndex("materialShortName");
            tbl.getViewManager().setFreezeView(-1, freezeCol + 1);
        } else
        {
            tbl.getColumn("materialShortName").getStyleAttributes().setHided(true);
            int freezeCol = tbl.getColumnIndex("materialName");
            tbl.getViewManager().setFreezeView(-1, freezeCol + 1);
        }
        int from = e.getFirstRow();
        int len = (e.getLastRow() - from) + 1;
        RptParams para = new RptParams();
        try
        {
            if(from == 0 && firstLoadData)
            {
                firstLoadData = false;
                para.setObject("dateFrom", params.getObject("dateFrom"));
                para.setObject("dateTo", params.getObject("dateTo"));
                para.setObject("storageOrg", params.getObject("fullSotrageOrg"));
                para.setObject("ckBxByStatUnit", params.getObject("ckBxByStatUnit"));
                para.setObject("kDRadioAll", params.getObject("kDRadioAll"));
                para.setObject("kDRadioOrder", params.getObject("kDRadioOrder"));
                para.setObject("kDRadioStock", params.getObject("kDRadioStock"));
                para.setObject("ckBxByStatUnit", params.getObject("ckBxByStatUnit"));
                para.setObject("ckBxShowMShortName", params.getObject("ckBxShowMShortName"));
                para.setString("shortNameFrom", params.getString("shortNameFrom"));
                para.setString("shortNameTo", params.getString("shortNameTo"));
                Object t = params.getObject("materialFrom");
                if(t != null)
                    para.setString("materialFrom", ((MaterialInfo)t).getNumber());
                t = params.getObject("materialTo");
                if(t != null)
                    para.setString("materialTo", ((MaterialInfo)t).getNumber());
                t = params.getObject("matGrFrom");
                if(t != null)
                    para.setObject("matGrFrom", (MaterialGroupInfo)t);
                t = params.getObject("matGrTo");
                if(t != null)
                    para.setObject("matGrTo", (MaterialGroupInfo)t);
                t = params.getObject("materialGroupStandard");
                if(t != null)
                    para.setObject("materialGroupStandard", (MaterialGroupStandardInfo)t);
                RptParams rp = StockTransferRptFacadeFactory.getRemoteInstance().createTempTable(para);
                setTempTable(rp.getString("tempTable"));
                tbl.setRowCount(rp.getInt("verticalCount"));
                para.setString("tempTable", getTempTable());
                RptParams rpt = StockTransferRptFacadeFactory.getRemoteInstance().query(para, from, len);
                RptRowSet rs = (RptRowSet)rpt.getObject("rowset");
                insertRows(rs, from, tbl, true, new DefaultKDTableInsertHandler(rs), 0);
                if(rs.getRowCount() == len)
                    getAllDataOfId();
            } else
            {
                java.util.List newList = new ArrayList(len);
                if(allIdList != null)
                {
                    for(int i = from; i < from + len && i < allIdList.size(); i++)
                        newList.add(allIdList.get(i));

                }
                if(newList != null && newList.size() > 0)
                {
                    para.setString("tempTable", getTempTable());
                    RptParams rpt = StockTransferRptFacadeFactory.getRemoteInstance().getDataForIdList(newList, para);
                    RptRowSet rs = (RptRowSet)rpt.getObject("rowset");
                    insertRows(rs, from, tbl, true, new DefaultKDTableInsertHandler(rs), insertRowCount);
                }
            }
        }
        catch(Exception ex)
        {
            handUIException(ex);
        }
    }

    public void insertRows(RptRowSet rs, int insertRowIndex, KDTable table, boolean refreshUI, KDTableInsertHandler handler, int insertRowCount)
    {
        table.setRefresh(false);
        int rowIndex = insertRowIndex + insertRowCount;
        if(rowIndex > 0)
        {
            int rIndex;
            for(rIndex = rowIndex - 1; rIndex > 0 && table.getRow(rIndex) == null; rIndex--);
            rowIndex = rIndex + 1;
        }
        int rowIndexStart = rowIndex;
        String oldMater = null;
        String newMater = null;
        String oldOrg = null;
        String newOrg = null;
        int qtyPrecision = 6;
        for(; rs.next(); rs.setValue("FOnWayAmt", rs.getBigDecimal("FOnWayAmt").setScale(amtPrecision, 4)))
        {
            qtyPrecision = rs.getInt("FQtyPrecision");
            rs.setValue("FIssueBaseQty", rs.getBigDecimal("FIssueBaseQty").setScale(qtyPrecision, 4));
            rs.setValue("FReceiptBaseQty", rs.getBigDecimal("FReceiptBaseQty").setScale(qtyPrecision, 4));
            rs.setValue("FOnWayBaseQty", rs.getBigDecimal("FOnWayBaseQty").setScale(qtyPrecision, 4));
            rs.setValue("FDamageBaseQty", rs.getBigDecimal("FDamageBaseQty").setScale(qtyPrecision, 4));
            rs.setValue("FIssueAmt", rs.getBigDecimal("FIssueAmt").setScale(amtPrecision, 4));
            rs.setValue("FDamageAmt", rs.getBigDecimal("FDamageAmt").setScale(amtPrecision, 4));
            rs.setValue("FAllocateQty", rs.getBigDecimal("FAllocateQty").setScale(qtyPrecision, 4));
            rs.setValue("FExportAmt", rs.getBigDecimal("FExportAmt").setScale(amtPrecision, 4));
            rs.setValue("FImportAmt", rs.getBigDecimal("FImportAmt").setScale(amtPrecision, 4));
            rs.setValue("FOriginalQty", rs.getBigDecimal("FOriginalQty").setScale(qtyPrecision, 4));
        }

        rs.reset();
        for(int i = 0; i < rs.getRowCount(); i++)
        {
            if(i != 0)
            {
                rs.moveTo(i - 1);
                oldMater = rs.getString("FMaterialID");
                oldOrg = rs.getString("FIssueOrgID");
                rs.moveTo(i);
                newMater = rs.getString("FMaterialID");
                newOrg = rs.getString("FIssueOrgID");
            } else
            {
                rs.moveTo(i);
                newMater = rs.getString("FMaterialID");
                newOrg = rs.getString("FIssueOrgID");
            }
            IRow row = table.addRow(rowIndex++);
            SimpleCompanyUserObject companyUserObject = new SimpleCompanyUserObject();
            companyUserObject.setCompanyId(rs.getString("FIssueOrgID"));
            companyUserObject.setName(rs.getString("FIssueStorageName"));
            companyUserObject.setBlockId(rs.getString("FMaterialID"));
            companyUserObject.setExpanded(false);
            int isleaf = rs.getInt("FIsLeaf");
            if(isleaf == 1)
                companyUserObject.setLeaf(true);
            else
                companyUserObject.setLeaf(false);
            if(newMater != null && !newMater.equals(oldMater) || newOrg != null && !newOrg.equals(oldOrg))
            {
                companyUserObject.setName(rs.getString("FIssueStorageName"));
            } else
            {
                companyUserObject.setName("");
                companyUserObject.setisIconEmpty(true);
            }
            companyUserObject.setLevel(rs.getInt("FLevel"));
            handler.setTableRowData(row, rs.toRowArray());
            ICell cell = row.getCell(getTreeCol());
            cell.setValue(companyUserObject);
            cell.setUserObject(companyUserObject);
        }

        if(refreshUI)
            table.setRefresh(true);
        else
            table.repaint();
        Object listeners[] = table.getListenerList().getListenerList();
        for(int i = listeners.length - 2; i >= 0; i -= 2)
            if(listeners[i] == (com.kingdee.bos.ctrl.kdf.table.event.KDTDataRequestListener.class))
                table.removeKDTDataRequestListener((KDTDataRequestListener)listeners[i + 1]);

        tbl_afterDataFill(rowIndexStart, rowIndexStart + rs.getRowCount());
        for(int i = listeners.length - 2; i >= 0; i -= 2)
            if(listeners[i] == (com.kingdee.bos.ctrl.kdf.table.event.KDTDataRequestListener.class))
                table.addKDTDataRequestListener((KDTDataRequestListener)listeners[i + 1]);

    }

    public void doExpand(SimpleCompanyUserObject companyUserObject, int rowIndex)
        throws Exception
    {
        int rowCount = getTable().getRowCount();
        if(companyUserObject.isLeaf() || companyUserObject.isIconEmpty())
            return;
        getTable().setRefresh(false);
        if(companyUserObject.isExpanded())
        {
            boolean isFirstExpanded = true;
            String compblockId = companyUserObject.getBlockId();
            for(int i = rowIndex + 1; i < rowCount; i++)
            {
                IRow row2 = getTable().getRow(i);
                SimpleCompanyUserObject company2 = (SimpleCompanyUserObject)row2.getCell(getTreeCol()).getValue();
                if(company2 == null)
                    continue;
                if(company2.getLevel() == companyUserObject.getLevel())
                {
                    if(!isFirstExpanded)
                        break;
                    continue;
                }
                if(company2.getLevel() <= companyUserObject.getLevel())
                    continue;
                if(!compblockId.equals(company2.getBlockId()))
                    break;
                row2.getStyleAttributes().setHided(true);
                if(company2.getLevel() == companyUserObject.getLevel() && row2.getStyleAttributes().isHided())
                    row2.getStyleAttributes().setHided(false);
            }

            companyUserObject.setExpanded(false);
        } else
        if(companyUserObject.isHasExpanded())
        {
            expandRow(rowIndex);
            companyUserObject.setExpanded(true);
        } else
        {
            RptParams pp = findData(rowIndex, companyUserObject);
            RptRowSet rs = (RptRowSet)pp.getObject("rowset");
            if(pp.getObject("LevelCount") != null)
            {
                insertRowIndex = pp.getInt("LevelCount");
                if(insertRowIndex == 0)
                    insertRowIndex = rowIndex + 1;
                else
                    insertRowIndex += rowIndex;
                insertRows(rs, insertRowIndex, getTable(), true, new DefaultKDTableInsertHandler(rs), 0);
            } else
            {
                insertRows(rs, rowIndex + 1, getTable(), true, new DefaultKDTableInsertHandler(rs), 0);
            }
            insertRowCount = insertRowCount + rs.getRowCount();
            getTable().setRowCount(getTable().getRowCount() + rs.getRowCount());
            setMergeRow(rowIndex);
            companyUserObject.setExpanded(true);
            companyUserObject.setHasExpanded(true);
        }
        getTable().setRefresh(true);
        getTable().reLayoutAndPaint();
    }

    private void setMergeRow(int rowIndex)
    {
        String mergeColumnKeys[] = getMergeColumnKeys();
        int mergeRowCount = 0;
        int mergeStartRow = 0;
        IRow row = getTable().getRow(rowIndex);
        String treeCol = getTreeCol();
        SimpleCompanyUserObject company = (SimpleCompanyUserObject)row.getCell(treeCol).getValue();
        if(company == null)
            return;
        for(int i = rowIndex; i >= 0; i--)
        {
            IRow row2 = getTable().getRow(i);
            SimpleCompanyUserObject company2 = (SimpleCompanyUserObject)row2.getCell(treeCol).getValue();
            if(company2 == null)
                continue;
            if(!company.getBlockId().equals(company2.getBlockId()))
                break;
            mergeStartRow = i;
        }

        for(int i = rowIndex; i < getTable().getRowCount(); i++)
        {
            IRow row2 = getTable().getRow(i);
            SimpleCompanyUserObject company2 = (SimpleCompanyUserObject)row2.getCell(treeCol).getValue();
            if(company2 == null)
                continue;
            if(company2.getLevel() == 1 && i > rowIndex || !company.getBlockId().equals(company2.getBlockId()))
                break;
            rowIndex++;
            mergeRowCount++;
        }

        int colIndex = 0;
        if(mergeColumnKeys != null && mergeColumnKeys.length > 0)
        {
            for(int i = 0; i < mergeColumnKeys.length; i++)
            {
                colIndex = getTable().getColumn(mergeColumnKeys[i]).getColumnIndex();
                KDTMergeManager mm = getTable().getMergeManager();
                boolean c = mm.mergeBlock(mergeStartRow, colIndex, rowIndex - 1, colIndex);
                System.out.println(c);
            }

        }
    }

    public String getUITitle()
    {
        return InvClientUtils.getResource("StockTransferMaterialRPT");
    }

    public String[] getMergeColumnKeys()
    {
        String strMergeColKeys[] = {
            "materialNum", "materialName", "materialShortName", "materialModel"
        };
        return strMergeColKeys;
    }

    public void onLoad()
        throws Exception
    {
        setMergeColumn();
        super.onLoad();
        btnView.setIcon(EASResource.getIcon("imgTbtn_bill"));
        int freezeCol = tbl.getColumnIndex("issueStorageOrg");
        tbl.getViewManager().setFreezeView(-1, freezeCol - 1);
    }

    public void checkSelected()
    {
        if(tbl.getSelectManager().size() == 0)
        {
            MsgBox.showWarning(this, EASResource.getString("com.kingdee.eas.framework.FrameWorkResource.Msg_MustSelected"));
            SysUtil.abort();
        }
    }

    public void actionView_actionPerformed(ActionEvent e)
        throws Exception
    {
        checkSelected();
        IRow row = tbl.getRow(getSelectRowIndex());
        if(row == null)
            return;
        Object temp = row.getCell("index").getValue();
        if(temp == null)
            return;
        if((temp instanceof Integer) && ((Integer)temp).intValue() != 0)
            return;
        if((temp instanceof BigDecimal) && ((BigDecimal)temp).compareTo(InvClientUtils.ZERO) != 0)
            return;
        UIContext uiContext = new UIContext(this);
        uiContext.put("dateFrom", dateFrom.getValue());
        uiContext.put("dateTo", dateTo.getValue());
        uiContext.put("ISSUEORGID", row.getCell("issueOrgID").getValue());
        uiContext.put("RECEIPTORGID", row.getCell("receiptOrgID").getValue());
        uiContext.put("MATERIALID", row.getCell("materialID").getValue());
        uiContext.put("MATERIALNAME", row.getCell("materialName").getValue());
        uiContext.put("MATERIALNUM", row.getCell("materialNum").getValue());
        uiContext.put("ISSUEORGNAME", row.getCell("parentid").getValue());
        uiContext.put("RECEIPTORGNAME", row.getCell("inStorageOrg").getValue());
        IUIWindow uiWindow = null;
        if(SwingUtilities.getWindowAncestor(this) != null && (SwingUtilities.getWindowAncestor(this) instanceof JDialog))
            uiWindow = UIFactory.createUIFactory(UIFactoryName.MODEL).create(getEditUIName(), uiContext, null, OprtState.VIEW);
        else
            uiWindow = UIFactory.createUIFactory(getEditUIModal()).create(getEditUIName(), uiContext, null, OprtState.VIEW);
        uiWindow.show();
    }

    private int getSelectRowIndex()
    {
        int rowIndex = -1;
        KDTSelectBlock selectBlock = tbl.getSelectManager().get();
        if(selectBlock != null)
            rowIndex = selectBlock.getTop();
        return rowIndex;
    }

    private String getEditUIName()
    {
        return (com.kingdee.eas.scm.im.rpt.client.StockTransferRptDetailUI.class).getName();
    }

    private String getEditUIModal()
    {
        return UIFactoryName.NEWWIN;
    }

    protected void tbl_tableClicked(KDTMouseEvent e)
        throws Exception
    {
        if(e.getClickCount() == 2)
        {
            ActionEvent evt = new ActionEvent(btnView, 0, "Double Clicked");
            ItemAction actView = getActionFromActionEvent(evt);
            actView.actionPerformed(evt);
        }
    }

    public RptParams findData(int rowIndex, SimpleCompanyUserObject companyUserObject)
        throws Exception
    {
        RptParams pp = new RptParams();
        IRow row = getTable().getRow(rowIndex);
        pp.setString("FMaterialID", row.getCell("materialID").getValue().toString());
        pp.setString("FParentID", companyUserObject.getCompanyId().toString());
        int level = companyUserObject.getLevel();
        pp.setInt("FLevel", level);
        pp.setString("tempTable", getTempTable());
        IVirtualRptBaseFacade report = getVirtualRemoteInstance();
        RptParams result = report.findData(pp, -1, -1, getTempTable(), companyUserObject);
        if(level == 1)
        {
            int t = result.getInt("LevelCount");
            if(t > 100)
            {
                int rowCount = tbl.getRowCount3();
                int s = (t - rowCount) + rowIndex;
                for(int i = 1; i <= s; i++)
                    tbl.getRow(rowCount + i);

            }
        }
        return result;
    }

    protected IVirtualRptBaseFacade getVirtualRemoteInstance()
        throws BOSException
    {
        return StockTransferRptFacadeFactory.getRemoteInstance();
    }

    public void tbl_afterDataFill(KDTDataRequestEvent e)
    {
        int from = e.getFirstRow();
        int last = e.getLastRow();
        for(int i = from; i <= last; i++)
        {
            Object scaleObj = tbl.getRow(i).getCell("qtyPrecision").getValue();
            if(scaleObj != null)
            {
                int scale = Integer.parseInt(scaleObj.toString());
                tbl.getRow(i).getCell("issueQty").getStyleAttributes().setNumberFormat(PrecisionUtil.getFormatString(scale));
                tbl.getRow(i).getCell("inQty").getStyleAttributes().setNumberFormat(PrecisionUtil.getFormatString(scale));
                tbl.getRow(i).getCell("onWayQty").getStyleAttributes().setNumberFormat(PrecisionUtil.getFormatString(scale));
                tbl.getRow(i).getCell("wayDamageQty").getStyleAttributes().setNumberFormat(PrecisionUtil.getFormatString(scale));
            }
        }

    }

    public void tbl_afterDataFill(int rowStart, int rowEnd)
    {
        int from = rowStart;
        int last = rowEnd;
        for(int i = from; i <= last; i++)
        {
            if(tbl.getRow(i) == null)
                continue;
            System.out.println(i);
            Object scaleObj = tbl.getRow(i).getCell("qtyPrecision").getValue();
            if(scaleObj != null)
            {
                int scale = Integer.parseInt(scaleObj.toString());
                tbl.getRow(i).getCell("issueQty").getStyleAttributes().setNumberFormat(PrecisionUtil.getFormatString(scale));
                tbl.getRow(i).getCell("inQty").getStyleAttributes().setNumberFormat(PrecisionUtil.getFormatString(scale));
                tbl.getRow(i).getCell("onWayQty").getStyleAttributes().setNumberFormat(PrecisionUtil.getFormatString(scale));
                tbl.getRow(i).getCell("wayDamageQty").getStyleAttributes().setNumberFormat(PrecisionUtil.getFormatString(scale));
            }
        }

    }

    protected void initListener()
    {
        super.initVirtualCompanyListener();
    }

    public String getTreeCol()
    {
        return "issueStorageOrg";
    }

    protected KDTable getTable()
    {
        return tbl;
    }

    protected void preparePrintPageHeader(HeadFootModel header)
    {
        StyleAttributes sa = Styles.getDefaultSA();
        StringBuffer sb = new StringBuffer();
        sb.append(EASResource.getString("com.kingdee.eas.scm.im.rpt.IMRptResource", "DATE_FROM")).append(" &[DateFrom]");
        sb.append("&|").append(EASResource.getString("com.kingdee.eas.scm.im.rpt.IMRptResource", "DATE_TO")).append(" &[DateTo]");
        sb.append("&|\u3000&|");
        header.addRow(sb.toString(), sa);
    }

    protected Map preparePrintVariantMap()
    {
        Map map = new HashMap();
        DateFormat df = DateFormat.getDateInstance(2);
        String temp = df.format((Date)params.getObject("dateFrom"));
        map.put("DateFrom", temp);
        temp = df.format((Date)params.getObject("dateTo"));
        map.put("DateTo", temp);
        return map;
    }

    protected boolean isAllowLoadPrintSetting()
    {
        return false;
    }

    private static final long serialVersionUID = 4514775218036135494L;
    private static final Logger logger;
    private static final String TB_ISSUEORGID = "issueOrgID";
    private static final String TB_RECEIPTORGID = "receiptOrgID";
    private static final String TB_MATERIALID = "materialID";
    private static final String TB_MATERIALNAME = "materialName";
    private static final String TB_MATERIALNUM = "materialNum";
    private static final String TB_ISSUEORGNAME = "issueStorageOrg";
    private static final String TB_ISSUEORGNAME2 = "parentid";
    private static final String TB_RECEIPTORGNAME = "inStorageOrg";
    private boolean firstLoadData;
    private int amtPrecision;

    static 
    {
        logger = CoreUIObject.getLogger(com.kingdee.eas.scm.im.rpt.client.StockTransferRptUI.class);
    }
}